﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Edge.Common.ComponentModel.Parameters;
using Edge.Common.Services;
using Shop.Business.Domain.Customers;
using Shop.Web.AppCode;

namespace Shop.Web
{
    public partial class Recover : ShopBasePage
    {
        [QueryParameter("key", IsRequired = true)]
        public string key;

        [QueryParameter("mail", IsRequired = true)]
        public string mail;

        protected void Page_Load(object sender, EventArgs e)
        {
            WebParameterAttribute.SetValues(this, Request);
            Customer customer = Locator.GetService<ICustomerManager>().GetContactByMail(mail);
            if (customer != null && customer.Passwrd == key)
            {
                if (!customer.RememberMe)
                {
                    customer.RememberMe = true;
                    Locator.GetService<ICustomerManager>().Save(customer);
                }
                SetCustomerHolder(customer);
            }
            Response.Redirect("Default.aspx");
        }
    }
}
